package talk.dapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.talk.debby.talk.R;

import java.util.List;

import talk.Bean.Video;
import talk.listener.OnVideoClick;

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.ViewHolder> {

    private List<Video> urls;
    private OnVideoClick click;
    private Context context;

    public VideoAdapter(Context context, List<Video> urls, OnVideoClick click) {
        this.context = context;
        this.urls = urls;
        this.click = click;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_video, parent, false);
        return new VideoAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.url.setText(urls.get(position).getName());

        holder.ll_video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                click.onClick(urls.get(position).getUrl());
            }
        });
    }

    @Override
    public int getItemCount() {
        return urls == null ? 0 : urls.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView url;
        LinearLayout ll_video;

        public ViewHolder(View view) {
            super(view);
            url = view.findViewById(R.id.tv_name);
            ll_video = view.findViewById(R.id.ll_video);
        }
    }
}
